﻿{% extends "base.html" %}



{% block css %}
<link rel="stylesheet" href="/static/css/admin.css">
<link rel="stylesheet" href="/static/ztree3/css/bootstrapStyle/bootstrapStyle.css" type="text/css">
{% endblock %}


{% block center %}


<!--头部导航-->
<div class="panel panel-default center-top" style="min-width:1300px;">
  <div class="panel-body">
    <ol class="breadcrumb" style="margin-bottom: 0px;background-color: #FFFFFF;">
      <li><a href="/" style="color: #377CD8;">首页</a></li>
      <li><a href="javascript:;">资产信息</a></li>
      <li class="active">{{ title }}</li>
    </ol>
  </div>
</div>



<!--用户信息-->
<div class="panel panel-default center-top" style="min-width:1300px;">
  <div class="panel-heading">
      <div class="row" style="padding-top:5px;padding-left:10px;">
          <div class="col-sm-6">

              <a href="javascript:;" class="btn btn-sm btn-success" data-toggle="modal" data-target="#idcModal"> 添加用户 </a>

          </div>
      </div>

  </div>
  <div class="panel-body">


        <div style="margin-bottom: 10px;">

            <div class="col-sm-12">
                <table class="table table-hover table-bordered">
                  <thead>
                    <tr style="background-color: #f5f5f5;">

                      <th>用户</th>
                      <th>负责人</th>
                      <th>手机号码</th>
                      <th>邮箱</th>
                      <th>秘钥</th>
                      <th>操作</th>
                    </tr>
                  </thead>
                  <tbody>

                  {% for i in login_user_list %}
                    <tr>

                      <td>{{ i.login_user }}</td>
                      <td>{{ i.last_name }}</td>
                      <td>{{ i.phone }}</td>
                      <td>{{ i.email }}</td>
                      {% if i.private_key == 'None' %}
                      <td>{{ i.private_key }}</td>
                      {% else %}
                      <td><a  style="text-decoration:none;" >已设置</a></td>
                      {% endif %}

                      <td style="padding-left:5px;">

                        <a href="javascript:;" style="text-decoration:none;" login_user_id="{{ i.login_user_id }}" name="edit-login-user" data-toggle="tooltip" data-placement="left" title="修改"><span class="fa fa-pencil"></span> </a>&nbsp;&nbsp;&nbsp;

                        <a href="javascript:;" style="text-decoration:none;" login_user_id="{{ i.login_user_id }}" name="del-login-user" data-toggle="tooltip" data-placement="right" title="删除"><span class="fa fa-trash"></span> </a>

                      </td>
                    </tr>
                  {% endfor %}
                  </tbody>
                </table>
                <div style="margin-top:-30px;padding-right:9%">
                  <ul class="pagination pull-right">
                    <li><a href="javascript:;">上一页</a></li>
                    <li><a href="javascript:;">1</a></li>
                    <li><a href="javascript:;">下一页</a></li>
                  </ul>

                </div>


            </div>

        </div>
  </div>
</div>


{% endblock %}


<!-- Modal -->
{% block modal %}

<div class="modal fade" id="idcModal" tabindex="-1" role="dialog" aria-labelledby="idcModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content" style="margin-top:135px;">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="idcModalLabel">添加登录用户</h4>
      </div>
      <div class="modal-body">

         <form>
          <div class="form-group">
            <label >用户名</label>
            <input  class="form-control"  placeholder="用户名" id="login-user">
          </div>
          <div class="form-group">
            <label >密码</label>
            <input  class="form-control" type="password" placeholder="密码" id="login-passwd">
          </div>
          <div class="form-group">
            <label >秘钥</label>
              <textarea  class="form-control"  placeholder="秘钥" id="login-key"></textarea>
          </div>
          <div class="form-group">
            <label >联系人</label>
              <select name="" id="people" class="form-control">
                  {% for i in user_list %}
                  <option value="{{ i.user_id }}">{{ i.username }}</option>
                  {% endfor %}
              </select>

          </div>
        </form>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary" id="sub-login-user">提交</button>
      </div>
    </div>
  </div>
</div>

<div class="modal fade" id="edit-idcModal" tabindex="-1" role="dialog" aria-labelledby="edit-idcModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content" style="margin-top:135px;">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="edit-idcModalLabel">添加登录用户</h4>
      </div>
      <div class="modal-body">

         <form>
          <div class="form-group">
            <label >用户名</label>
            <input  class="form-control"  placeholder="用户名" id="edit-login-user">
          </div>
          <div class="form-group">
            <label >密码</label>
            <input  class="form-control" type="password" placeholder="密码" id="edit-login-passwd">
          </div>
          <div class="form-group">
            <label >秘钥</label>
              <textarea  class="form-control"  placeholder="秘钥" id="edit-login-key"></textarea>
          </div>
          <div class="form-group">
            <label >联系人</label>
              <select name="" id="edit-people" class="form-control">
                  {% for i in user_list %}
                  <option value="{{ i.user_id }}">{{ i.username }}</option>
                  {% endfor %}
              </select>

          </div>
        </form>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary" id="edit-sub-login-user">提交</button>
      </div>
    </div>
  </div>
</div>


{% endblock  %}

{% block js %}
    <script type="text/javascript" src="/static/js/cmdb.js"></script>

    <script type="text/javascript" >

        //////////////////远程登录用户管理///////////////////////

        $("#sub-login-user").click(function(){

            var login_user = $("#login-user").val();
            var login_passwd = $("#login-passwd").val();
            var login_key = $("#login-key").val();
            var people = $("#people").val();
            if(login_user && login_passwd){
                $.post("/cmdb/addlguser/",{"login_user":login_user,"login_passwd":login_passwd,"login_key":login_key,"people":people},function(data){

                    alert(data);
                    location.reload();
                });
            }else{

                alert("用户密码不能为空")
            }

        });

        //编辑修改内容
        $("td a[name='edit-login-user']").click(function(){
            var login_user_id = $(this).attr('login_user_id');
            $.post("/cmdb/editlguser/",{'login_user_id':login_user_id},function(data){
                if (data == "权限不足"){
                    alert("权限不足，请联系管理员！");
                }else{

                var info = eval('(' + data + ')');
                $("#edit-login-user").val(info.login_user);
                $("#edit-login-passwd").val(info.login_passwd);
                $("#edit-login-key").val(info.private_key);
                $("#edit-people").val(info.people);
                $("#edit-sub-login-user").attr('login_user_id',info.login_user_id);
                $("#edit-idcModal").modal('show');
                }
            })
        });


        //修改
        $("#edit-sub-login-user").click(function(){
            var login_user_id = $(this).attr("login_user_id");
            var login_user = $("#edit-login-user").val();
            var login_passwd = $("#edit-login-passwd").val();
            var login_key = $("#edit-login-key").val();
            var people = $("#edit-people").val();
            $.post("/cmdb/editlguser/",{'action':'edit',"login_user_id":login_user_id,"login_user":login_user,"login_passwd":login_passwd,"login_key":login_key,"people":people},function(data){
            if (data == "权限不足"){
                    alert("权限不足，请联系管理员！");
                }else{

                alert(data);
                if (data == "修改成功"){
                    location.reload();
                }
            }
            })

        });


        //删除
        $("td a[name='del-login-user']").click(function(){
           var login_user_id = $(this).attr('login_user_id');
           var statu = confirm("是否确认删除！");
           if (statu==true)
            {
                $.post("/cmdb/dellguser/",{'login_user_id':login_user_id},function(data){

                    if (data == "权限不足"){
                            alert("权限不足，请联系管理员！");
                        }else{

                        if (data == "已删除"){
                            location.reload();
                        }
                    }
                })
            }
        });


    </script>

{% endblock %}


